package vh.sphynx.runtime.impl;

import java.util.HashMap;
import java.util.Map;

import vh.sphynx.runtime.ExecutionContext;
import vh.sphynx.runtime.VariableStorage;

public class DependentExecutionContext extends DefaultExecutionContext {

	public DependentExecutionContext(ExecutionContext parentContext,
			ExecutionContext callerContext) {
		super(parentContext, callerContext);
	}

	@Override
	public VariableStorage getVariable(String qualifiedName,
			boolean allowCreateNew, boolean recursive) {
		VariableStorage var = super.getVariable(qualifiedName, allowCreateNew, recursive);
		if (var == null && !recursive && parent != null)
			var = parent.getVariable(qualifiedName, allowCreateNew, recursive);
		return var;
	}
	
	@Override
	protected Map<String, VariableStorage> getAllVariables() {
		Map<String, VariableStorage> temp = new HashMap<String, VariableStorage>(((DefaultExecutionContext) parent).getAllVariables());
		temp.putAll(variables);
		return temp;
	}	
}
